package cool.taomu.demo

import com.google.gson.Gson
import cool.taomu.entity.DataEntity
import cool.taomu.entity.DataEntity.LanguageType
import cool.taomu.entity.TimerTaskEntity
import cool.taomu.thread.NetworkThread
import cool.taomu.utils.ThriftUtils
import java.io.File
import java.nio.ByteBuffer
import org.apache.commons.io.FileUtils
import org.apache.commons.lang3.SerializationUtils

class Demo {
	def static void deploy() {
		var a = "/home/rcmu/workspace/demo";
	/*var se =new SenderEntity("taomu/deploy");
	 * se.broker("c222.taomu.cool",1883,"","").message = dp.toSerializable;
	 se.sendClone;*/
	}
	
	def static void test(){
		var String code = FileUtils.readFileToString(new File("./usecase/test.json"),"UTF-8");
		println(code)
		var t = new Gson().fromJson(code,DataEntity);
		println(t);
	}

	def static void execute() {
		var String json = FileUtils.readFileToString(new File("./usecase/testTask.json"),"UTF-8");
		var String code = FileUtils.readFileToString(new File("./usecase/SinaStock.groovy"),"UTF-8");
		var host = "192.168.1.223";
		var port = 8090;
		val data = new Gson().fromJson(json,DataEntity);
		data.script = code;
		ThriftUtils.rpc(host, port, [
			var NetworkThread.Client client = new NetworkThread.Client(it);
			client.execute(ByteBuffer.wrap(SerializationUtils.serialize(data)));
		])
	}

	def static void main(String[] args) {
		// deploy();	
		execute()
	}
}
